﻿Imports System.Data.SqlClient
Imports System.IO
Imports Sendkey = System.Windows.Forms.SendKeys
'Imports System.Threading

Public Class FrmMateriaTipoAsunto_Editar

#Region "Variables"

    Private cGeneral As New clsGeneral
    Private cAreas As New clsAreas

    Dim dtAreas As New DataTable()
    Dim NuevaFila As DataRow

#End Region

#Region "Eventos"

    Private Sub FrmMateriaTipoAsunto_Editar_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        gs_Hilera = Txt_MateriaTipoAsunto.Text
        gi_Codigo_1 = Cmb_Areas.SelectedValue
        gi_Codigo_2 = Txt_Plazo_Meses.Text
    End Sub

    Private Sub FrmMateriaTipoAsunto_Editar_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        gs_Pantalla = Me.Name

        dtAreas.Clear()
        dtAreas = cAreas.ObtenerAreas("Alfabetico")
        NuevaFila = dtAreas.NewRow
        NuevaFila.Item("Area") = 9  ' valor NO almacenado en la tabla
        NuevaFila.Item("Nombre") = ".Todas las Areas"
        dtAreas.Rows.Add(NuevaFila)
        ' reordena el DataTable
        'dtAreas = dtAreas.Select(Nothing, "Nombre asc").CopyToDataTable()
        dtAreas = cGeneral.DataTable_Filtrar_Ordenar(dtAreas, "", "Nombre")
        Cmb_Areas.DataSource = dtAreas
        Cmb_Areas.ValueMember = dtAreas.Columns(0).ToString
        Cmb_Areas.DisplayMember = dtAreas.Columns(1).ToString

        If Me.Text = "Insertar" Then
            Txt_MateriaTipoAsunto.Text = ""
            Cmb_Areas.SelectedIndex = 0
            Txt_Plazo_Meses.Text = ""
        Else
            Txt_MateriaTipoAsunto.Text = gs_Hilera
            Cmb_Areas.SelectedValue = gi_Codigo_1
            Txt_Plazo_Meses.Text = gi_Codigo_2
        End If

    End Sub

    Private Sub Txt_MateriaTipoAsunto_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Txt_MateriaTipoAsunto.KeyPress
        If Asc(e.KeyChar) = Keys.Return Then
            Sendkey.Send("{tab}")
        ElseIf Asc(e.KeyChar) <> 8 Then
            If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ ", Char.ToUpper(e.KeyChar)) = 0 Then
                MessageBox.Show("Caracter inválido, use letras")
                e.Handled = True
            End If
        End If
    End Sub

    Private Sub Txt_Plazo_Meses_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Txt_Plazo_Meses.KeyPress
        If Asc(e.KeyChar) = Keys.Return Then
            Sendkey.Send("{tab}")
        ElseIf Asc(e.KeyChar) <> 8 Then
            If InStr("0123456789", Char.ToUpper(e.KeyChar)) = 0 Then
                MessageBox.Show("Caracter inválido, use dígitos")
                e.Handled = True
            End If
        End If
    End Sub

    Private Sub Txt_Plazo_Meses_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Txt_Plazo_Meses.Validating
        If Txt_Plazo_Meses.Text.Trim = "" Then
            Txt_Plazo_Meses.Text = "0"
        End If
    End Sub

    Private Sub Btn_Aceptar_Click(sender As Object, e As EventArgs) Handles Btn_Aceptar.Click
        Me.Close()
    End Sub

    Private Sub Btn_Cancelar_Click(sender As Object, e As EventArgs) Handles Btn_Cancelar.Click
        Txt_MateriaTipoAsunto.Text = ""
        Cmb_Areas.SelectedValue = 9
        Txt_Plazo_Meses.Text = "0"
        Me.Close()
    End Sub

#End Region

End Class